class Solution {
public:
    int jump(vector<int>& nums) {
        int cur = 0, next = 0;
        int ans = 0;
        for(int i = 0; i < nums.size() - 1; ++i)
        {
            next = max(next, i + nums[i]);
            if(i == cur)
            {
                ++ans;
                cur = next;
            }
        }
        return ans;
    }
};
